﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XNAGameEngine;
using XNAGameEngine.GameObject;
using XNAGameEngine.Utility;
using XNAGameEngine.DataStructures;

namespace XNAGameEngine
{
    public class map
    {
        public tile[,] grid = new tile[10, 10];
        public int[] TileIDs = new int[100];

        public tile[,] Grid
        { get { return this.grid; } }


        public map()
        {
            loadmap();
        }

        public void loaddudes()
        {

        }

        public void loadmap()
        {
            // will do infile later
            // need to figure out height modifier
            int heightmod = 0;
            int k = 0;


            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {

                    TileIDs[k] = GameEngine.GetService<IManagerGameObject2D>().CreateGameObject("Tile");
                    grid[i, j] = (tile)GameEngine.GetService<IManagerGameObject2D>().GetGameObjectById(TileIDs[k]);
                    grid[i, j].X = i;
                    grid[i, j].Y = j;
                    if (grid[i, j].X + grid[i, j].Y == 0)
                        grid[i, j].Z = 1;
                    else
                        grid[i, j].Z = 1 / (i + j + .01f);

                    grid[i, j].Screenx = (320 - (i * 32) + (j * 32));
                    //need to do infile to get height
                    grid[i, j].Screeny = (100 + (j * 16) + (i * 16) - (heightmod * 1));
                    grid[i, j].Occupant = "";
                    grid[i, j].warOccupant = null;
                    grid[i, j].Occupiable = true;
                    k++;

                }
            }
        }

        public void DestroyMap()
        {
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    grid[i, j].Destroy();
                } 
            }
        }



    }
}
